package com.haha.helloworld.event;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;

public class MyButton extends AppCompatButton {


    public MyButton(@NonNull Context context) {
        super(context);
    }

    public MyButton(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d("Mybutton","--onTouchEvent--");
                break;
        }
        //事件的冒泡机制：Mybutton里边的onTouchEvent被调用，那它的上一层的onTouchEvent也会被调用
        //返回的布尔值为false，就表示冒泡机制执行
        //返回的布尔值为true，就表示冒泡机制不执行
        return super.onTouchEvent(event);
    }
}
